$(function () {
	if($("#userId").attr("idnum")=="" || $("#userId").attr("idnum")==undefined){
		window.location.href="wsgrxx.html"
	}else{
		if(localStorage.customerNo!==""){
			$(".zjlx").val("00");
			$(".zjhm").val($("#userId").attr("idnum"));
		}else{
			alert("请先绑定市民卡！")
			window.location.href="front/smkservice/smkbd.do"
		}
		
	}

    getklx();
    $("body").on("click",".gssmkDiv",function () {
        if ($(this).attr("xt")=="0"){
            $(this).addClass("gssmkxz");
            $(this).attr("xt","1")
        }else if($(this).attr("xt")=="1"){
            $(this).removeClass("gssmkxz");
            $(this).attr("xt","0")
        }
    })

    $(".gscximg").click(function () {
        var data = {
            paperType : $.trim($(".zjlx option:selected").val()),
            paperNo : $.trim($(".zjhm").val()),
            startLine : 0,
            numPerPage : 20,
            currentPage : 1
        };
        $.ajax({
            url:"front/queryLossCard.do",
            type:"POST",
            data: data,
            dateType:"XML",
            success:function (xml) {
            if (xml.code == 0){
            $(xml.data).each(function (n,m) {
                var gscard = $("<div class='gssmkDiv' xt='0'><div class='gssmkkh'>"+m.citizenCardNo+"</div><div class='kcp'>卡产品：<span class='kpc'>"+m.cardPName+"</span></div><div class='klx'>卡类型：<span class='klx'>"+m.cardPhysicsTypeName+"</span></div><div class='gsname'>姓名：<span class='name'>"+m.customerName+"</span></div><div class='gszjh'>证件号：<span class='zjh'>"+m.paperNo+"</span></div></div>").appendTo(".xygssmk");
            })
                $(".smkxxcx").attr("src","static/img/cx0.png");
                $(".gskxz ").attr("src","static/img/xzsml1.png");
                $(".gsztDiv1").css("display","none");
                $(".gsztDiv2").css("display","block");
            }else {
             alert(xml.message)
            }
                }
            })


    })
    $(".xyb").click(function () {
    if ($(".gssmkDiv.gssmkxz").length>1){
        alert("一次挂失只能选择一张市民卡！")
    }else if($(".gssmkDiv.gssmkxz").length==0){
       alert("请选择市民卡");
    }else{
        $(".gssmkDiv.gssmkxz").each(function (i,o) {
            if($(o).attr("xt") == "1"){
                var data = {
                    citizenCardNo : $.trim($(this).find(".gssmkkh").text()),
                    cardPName : $.trim($(this).find(".kpc").text()),
                    customerName : $.trim($(this).find(".name").text()),
                    paperTypeName : $.trim($(this).find(".klx").text()),
                    paperNo : $.trim($(this).find(".zjh").text()),
                    cardStatus : "2"
                }
                $.ajax({
                    url:"front/commitLossCardInfo.do",
                    type:"POST",
                    data:data,
                    dataType:"JSON",
                    success:function (json) {
                        if(json.code==0){
                            var div = $(" <div class='gswcdiv'><img src='static/img/gswc.png'></div><div class='wcts'>恭喜您，挂失成功</div><div class='wcnr'>您本次挂失的凭证号为 <span>"+json.data.certNo+"</span></div><div class='gohomediv'><a href='qzsmk.html'><img src='static/img/gohome.png' class='gohome'></a></div>").appendTo(".gsztDiv3");
                            $(".gskxz").attr("src","static/img/xzsmk0.png");
                            $(".gswc ").attr("src","static/img/gswc1.png");
                            $(".gsztDiv2").css("display","none");
                            $(".gsztDiv3").css("display","block");
                        }
                    }
                })

            }else{

            }
        })
    }


    })
})

function getklx() {
    $.ajax({
        url:"front/queryAllCertificates.do",
        type:"GET",
        dataType:"json",
        success:function (json) {
            if (json.code == 0){
                $(json.data).each(function (i,o) {
                    var option = $("<option value ='"+o.certificateType+"' >"+o.certificatesName+"</option>").appendTo(".zjlx");
                })
            }else if (json.code ==1){
                alert("市民卡类型获取错误！");
            }
        }
    })
}